<form class="layui-form model-form" id="form-psw">
    <div class="layui-form-item">
        <label class="layui-form-label">原始密码:</label>
        <div class="layui-input-block">
            <input type="password" name="oldPsw" placeholder="请输入原始密码" class="layui-input"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码:</label>
        <div class="layui-input-block">
            <input type="password" name="newPsw" placeholder="请输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|psw" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码:</label>
        <div class="layui-input-block">
            <input type="password" name="rePsw" placeholder="请再次输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|repsw" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="submit-psw" lay-submit>保存</button>
        </div>
    </div>
</form>

<script>
    layui.use(['layer', 'form','printer','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var printer = layui.printer;

        // 监听提交
        form.on('submit(submit-psw)', function (data) {
        	var url ='sys/user/updatePwd';
            layer.load(2);
            admin.req(url, data.field, function (res) {
                layer.closeAll('loading');
                if (res.code==200) {
                    layer.msg(res.message, {icon: 1});
                } else {
                    layer.msg(res.message, {icon: 2});
                }
            }, 'post');
            return false;
        });

        // 添加表单验证方法
        form.verify({
//            psw: [/^[\S]{5,12}$/, '密码必须5到12位，且不能出现空格'],
			psw:[/^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*])[\da-zA-Z~!@#$%^&*]{8,}$/, '必须包含数字、英文字母、特殊符号且大于等于8位,且不能出现空格'],
            repsw: function (t) {
                if (t !== $('#form-psw input[name=newPsw]').val()) {
                    return '两次密码输入不一致';
                }
            }
        });

    });
</script>